<?php
include "sql.php";
include "time.php";

$where=$_GET['where'];
$search=$_GET['search'];
$page=$_GET['page'];
if($where==NULL||$page==NULL||$search==NULL||($where!='ws'&&$where!='dxc'))
    header("location: http://1.quanyibuscut.sinaapp.com/quanxiaoyi/index.html");

$begin=($page-1)*10;
if($where=='ws')
{
    $sql="select * from proposal_main where (type='11'||type='12'||type='13'||type='14')&&(title like '%$search%') order by time desc,ID desc limit 10 offset $begin ";
    $sql2="select count(*) from proposal_main where (type='11'||type='12'||type='13'||type='14')&&(title like '%$search%')";
}
else if($where=='dxc')
{
    $sql="select * from proposal_main where (type='21'||type='22'||type='23'||type='24') and title like '%$search%' order by time desc,ID desc limit 10 offset $begin ";
    $sql2="select count(*) from proposal_main where where (type='21'||type='22'||type='23'||type='24') and title like '%$search%'";

}
$arr2=SQL_turnarr(SQL_query($sql));//获得提案分页数据，转换成数组
$maxID=SQL_turnarr(SQL_query($sql2));
$maxID=$maxID[0][0];
$maxpage=(int)($maxID/10+1);//获得提案总条数与页码
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
        <link rel="stylesheet" type="text/css" href="../css/stylesheet.css">
        <title>华工权小益提案收集平台</title>
        <script type="text/javascript">
        var page_current=<?php echo $page;?>;
        function initLoad(){
        if(page_current==1){
            document.getElementById('page_prev').style.color='gray';
        }
        if(page_current==<?php echo $maxpage;?>){
         document.getElementById('page_next').style.color='gray';   
        }
        }
        onload=initLoad;
        function OnPrevPage(){
            if(page_current>1){

                page_current--;
                window.location.href='list_search_result.php?where=<?php echo $where;?>&page='+page_current+'&search=<?php echo $search;?>';                
            }

        }
        function OnNextPage(){
            if(page_current<<?php echo $maxpage;?>){
                page_current++;
                window.location.href='list_search_result.php?where=<?php echo $where;?>&page='+page_current+'&search=<?php echo $search;?>';                
            }
        }
        </script>
    </head>
    <body>
        <div class="header">
            <a href="../index.html"><img src="../img/newhead.jpg"></a>
        </div>
        <div class="clear"></div>
		<div class="typehead typehead1"><span><?php echo $type;?></span><a href="<?php if($_GET['where']=='ws') echo "wstype.html";else if($_GET['where']=='dxc')echo "dxctype.html"?>"><span style="float:right;">↰返回&nbsp;&nbsp;</span></a></div>
        <div id="a" style="color:#FFFFFF";>&nbsp;搜索“<?php echo $search;?>”的结果:(共<?php echo $maxID;?>条&nbsp;第<?php echo $page;?>页/共<?php echo $maxpage;?>页)</div>
        <!-- 需要从数据库中读取此类消息的名称时间以及热度指数，然后直接就显示出来了。一下各类都很类似就不在其他的html文件里面注释了 -->
        <div class="prolist">
            <table>
                <tbody>
                    <tr>
                        <td>提案名称</td>
                        <td>提案时间</td>
                        <td>热度</td>
                    </tr>
                    <?php 
                        $i=0;
                        for($j=0;$j<10;$j++)
                        {
                            $hot=$arr2[$i]['praise']+$arr2[$i]['score_time']*2;//计算热度指数，如果提案为NULL则也显示NULL
                            if($arr2[$i]['ID']==NULL)
                                $hot=NULL;
                            echo '
                            <tr>
                                <td>';
                            if($arr2[$i]['ID']!=NULL)
                                echo '
                                    <a href="detail.php?proposal_id='.$arr2[$i]['ID'].'&type='.$typeID.'">'.
                                        $arr2[$i]['title'].'
                                    </a>';
                            echo '
                                </td>
                                <td>'.time_echo($arr2[$i++]['time'],1).'</td>
                                <td>'.$hot.'</td>
                            </tr>';
                        }
                    ?>
                </tbody>
            </table>
            <div class="changepage">
                <div class="page" id="page_prev" onclick="OnPrevPage();" style="cursor:pointer;color:#FFFFFF;">&lt;&lt;Prev</div>
                <div class="page page2" id="page_next" onclick="OnNextPage();" style="cursor:pointer;color:#FFFFFF;">Next&gt;&gt;</div>
            </div>
        </div>
        <div class="clear"></div>
        <div class="wholecori">
            <div class="copyright">
                <span>Copyright © 2014 华南理工大学学生会权益部</span>
            </div>
            <div class="copyright">
                <span>Power by 无线电爱好者协会信息部</span>
            </div>
        </div>
        <div class="clear"></div>
    </body>
</html>